'use strict';
const nodemailer = require('nodemailer');

// async..await is not allowed in global scope, must use a wrapper
async function main() {
    // Generate test SMTP service account from ethereal.email
    // Only needed if you don't have a real mail account for testing
    //let testAccount = await nodemailer.createTestAccount();

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
        service: 'QQ', // 如果使用QQservice,密码需要使用qq授权码
        auth: {
            user: '1669738430@qq.com',
            pass: 'authCode'
        }
    });

    // send mail with defined transport object
    let info = await transporter.sendMail({
        from: '1669738430@qq.com', // sender address
        to: '1669738430@qq.com', // list of receivers
        subject: 'Hello ✔', // Subject line
        text: 'Hello world?', // plain text body
        html: '<b>Hello world?</b>' // html body
    });

    console.log('Message sent: %s', info.messageId);
}

main().catch(err => {
    console.log(err);
});
